import java.util.*;
interface IntegerStack{
    public Integer push(Integer item); //如item为null，则不入栈直接返回null。否则直接入栈，然后返回item。
    public Integer pop();              //出栈，如栈为空，则返回null。
    public Integer peek();             //获得栈顶元素，如栈顶为空，则返回null。注意：不要出栈
    public boolean empty();           //如过栈为空返回true
    public int size();                //返回栈中元素数量
}


class ArrayListIntegerStack implements IntegerStack{
    private List<Integer> list;
    ArrayListIntegerStack(){
        list = new ArrayList<Integer>();
    }
    public Integer push(Integer item) {
        if(item == null) {
            return null;
        }
        list.add(item);
        return item;
    }
    public Integer pop() {
        int idx = list.size();
        if(list.isEmpty()) {
            return null;
        }
        int top = list.get(idx-1);
        list.remove(idx-1);
        return top;
    }
    public Integer peek() {
        if(list.isEmpty()) {
            return null;
        }
        int idx = list.size();
        return list.get(idx-1);
    }
    public boolean empty() {
        return list.isEmpty();
    }
    public int size() {
        return list.size();
    }
    @Override
    public String toString() {
        return list.toString();
    }
}


public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        ArrayListIntegerStack list = new ArrayListIntegerStack();
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        for(int i = 0; i<m; i++) {
            int temp = scan.nextInt();
            System.out.println(list.push(temp));
        }
        System.out.println(list.peek()+","+list.empty()+","+list.size());
        System.out.println(list);
        int x = scan.nextInt();
        for(int i = 0; i<x; i++) {
            System.out.println(list.pop());
        }
        System.out.println(list.peek()+","+list.empty()+","+list.size());
        System.out.println(list);
        scan.close();



    }

}